#include "mainwindow.h"
#include <QDesktopServices>
#include <QUrl>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->setGeometry(0, 0, 800, 480);
    mCheckBox = new QCheckBox(this);
    mCheckBox->setGeometry(350, 200, 250, 50);
    mCheckBox->setCheckState(Qt::Checked);
    mCheckBox->setText("初始化为Checked状态");
    mCheckBox->setTristate();
    connect(mCheckBox, &QCheckBox::stateChanged,
            this, &MainWindow::onCheckBoxStateChangeListener);

    mCommandLinkButton = new QCommandLinkButton("打开C：", "open C: path", this);
    mCommandLinkButton->setGeometry(350, 400, 250, 50);
    connect(mCommandLinkButton, &QCommandLinkButton::clicked,
            this, &MainWindow::onCommandLinkButtonClickListener);
}

MainWindow::~MainWindow()
{

}

void MainWindow::onCheckBoxStateChangeListener(int state)
{
    switch (state) {
    case Qt::Checked:
        mCheckBox->setText("选中");
        break;
    case Qt::Unchecked:
        mCheckBox->setText("非选中");
        break;
    case Qt::PartiallyChecked:
        mCheckBox->setText("半选中");
        break;
    }
}

void MainWindow::onCommandLinkButtonClickListener()
{
    QDesktopServices::openUrl(QUrl("C:/"));
}
